package com.example.emaildemo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    private final static String code = "12345";
    @Autowired
    private JavaMailSenderImpl javaMailSenderImpl;

    public String sendEmail(String email){
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        String captcha = code;
        simpleMailMessage.setSubject("验证码邮件:");
        simpleMailMessage.setFrom("smarmot@163.com");
        simpleMailMessage.setTo(email);
        simpleMailMessage.setText("验证码为：" + code);
        System.out.println(javaMailSenderImpl.getHost() + "," + javaMailSenderImpl.getPort());
        javaMailSenderImpl.send(simpleMailMessage);
        return code;
    }
}
